package L1;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

public class CompletableFutureBuildDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture<Void> completableFuture = CompletableFuture.runAsync(() -> {
            System.out.println(Thread.currentThread().getName());
        });
        System.out.println(completableFuture.get());


        CompletableFuture<Object> completableFuture2 = CompletableFuture.supplyAsync(() -> {
            return new Object();
        }).whenComplete((v, e) -> {
            if (e == null) {
                System.out.println("--计算完成");
            }
        }).exceptionally(e->{
            e.printStackTrace();
            System.out.println("异常为："+e.getCause()+"  "+e.getMessage());
            return null;
        });
        System.out.println(completableFuture2.get());
    }
}
